package com.laicunba.service.impl.udcredit;

import org.apache.commons.lang3.RandomStringUtils;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.util.Map;

/**
 * 实名认证规则调用Demo.
 * 
 * @author hush@bsfit.com.cn
 * @version 1.0
 * @date 10/29/15
 */
public class GeneralDemo {

	public static void main(String[] args) {

		Map<String, String> param = ParameterFactory.getShimingParameterMap("张三", "330382199910102222", "12341234");
		AntifraudRequest request = new AntifraudRequest();

		request.setPartnerCode(DemoConfig.PARTNER_CODE);
		request.setNonceStr(RandomStringUtils.randomNumeric(32));
		request.setStrategyCode(DemoConfig.SHIMING_STRATEGY_CODE);
		request.setScenarioCode(DemoConfig.SHIMING_SENARIO_CODE);
		request.setPackageStr(SignatureHelper.generateSignedPackageStr(param));
		request.setSignature(SignatureHelper.generateSignatureFromRequest(DemoConfig.SECRET_KEY, request));

		System.out.println(request);

		HttpRequestSimple httpRequestSimple = new HttpRequestSimple();
		String response = httpRequestSimple.postSendHttp(DemoConfig.SERVICE_URL, request.toString());
		System.out.println(response);
		try {
			JSONObject json = (JSONObject) new JSONParser().parse(response);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

}
